from django import forms

class BootstrapModeForm(forms.ModelForm):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        #循环找到所有插件，并添加样式
        for name, field in self.fields.items():
            if field.widget.attrs:
                field.widget.attrs["class"] = "form-control"
                field.widget.attrs["placeholder"] = field.label

            else:
                field.widget.attrs = {"class": "form-control", "placeholder": field.label}



class BootstrapForm(forms.Form):
    bootstrap_exclude_fields = []


    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        #循环找到所有插件，并添加样式
        for name, field in self.fields.items():
            if name in self.bootstrap_exclude_fields:
                continue
            if field.widget.attrs:
                field.widget.attrs["class"] = "form-control"
                field.widget.attrs["placeholder"] = field.label

            else:
                field.widget.attrs = {"class": "form-control", "placeholder": field.label}
